﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Inovout.ArcGis;
using Inovout.Gis;
using Inovout.Gis.Job;

namespace ArgGisUI
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.CheckFileExists = true;
                openFileDialog.Multiselect = false;
                openFileDialog.RestoreDirectory = true;
                openFileDialog.Filter = "ArcMap Documents (*.mxd)|*.mxd|ArcMap Templates (*.mxt)|*.mxt|Published Maps (*.pmf)|*.pmf|所有支持Map的格式|*.mxd;*.mxt;*.pmf";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    mapControl.Load(openFileDialog.FileName);
                    //  axTOCControl.SetBuddyControl(mapControl);

                    //    ICommand command = new ControlsSelectFeaturesToolClass();
                    //    command.OnCreate(mapControl.Object);
                    //    mapControl.CurrentTool = command as ITool;

                    //    mapControl.OnSelectionChanged += new EventHandler(axMapControl_OnSelectionChanged);
                    //}
                }
            }
        }



        private void layerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable<ILayerInfo> layerInfos = mapControl.MapInfo.Layers;
            StringBuilder stringBuilder = new StringBuilder();
            foreach (var layerInfo in layerInfos)
            {
                BuildLayerInfoDescription(layerInfo, stringBuilder);
            }
            MessageBox.Show(stringBuilder.ToString());
        }

        private void BuildLayerInfoDescription(ILayerInfo layerInfo, StringBuilder stringBuilder)
        {
            LayerInfo layer = layerInfo as LayerInfo;
            stringBuilder.AppendFormat("Layer Name:{0}", layerInfo.Name);
            stringBuilder.AppendLine();
            if (layer is GroupLayerInfo)
            {
                GroupLayerInfo groupLayer = layerInfo as GroupLayerInfo;
                foreach (var children in groupLayer.Layers)
                {
                    BuildLayerInfoDescription(children, stringBuilder);
                }
            }
        }

        private void dlReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
          //  JQNTuBanLayer.Instance.GetTuBans();
            //  List<FLMJX> items = JQNTuBanLayer.Instance.GetDLMJXs();
        }

        private void modifyLineAreaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new CalculateGeometoryNetAreaJob().Execute(null);
        }

        private void showMessageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new MessageForm().ShowDialog();
        }
    }
}
